package com.muqi.app.qlearn.adapter;

import java.util.List;

import com.easemob.easeui.widget.CircularImage;
import com.muqi.app.network.http.GlideImageUtils;
import com.muqi.app.project.utils.TimeMangerUtil;
import com.muqi.app.qlearn.modles.NoticeBean;
import com.muqi.app.qlearn.student.R;
import com.muqi.app.user.widget.CircularImageView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.TimeUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NoticeAdapter extends BaseAdapter {
	private Context context;
	private List<NoticeBean> listData;
	private OnHomeWorkListener listener = null;

	public NoticeAdapter(Context context, List<NoticeBean> listData, OnHomeWorkListener listener) {
		this.context = context;
		this.listData = listData;
		this.listener = listener;
	}

	@Override
	public int getCount() {
		return listData == null ? 10 : listData.size();
	}

	@Override
	public NoticeBean getItem(int position) {
		return listData.get(position);
	}
   
	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams") @Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		final NoticeBean itemInfo = listData.get(position);
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_my_notice, null);
			holder.itemAvatar = (CircularImageView) convertView.findViewById(R.id.homewk_logo);
			holder.itemButton = (ImageView) convertView.findViewById(R.id.homewk_delete);
			holder.itemName = (TextView) convertView.findViewById(R.id.homewk_name);
			holder.itemTime = (TextView) convertView.findViewById(R.id.homewk_time);
			holder.itemContent = (TextView) convertView.findViewById(R.id.homewk_content);
			holder.itemflower = (TextView) convertView.findViewById(R.id.homewk_follwer);
			holder.itemunread = (TextView) convertView.findViewById(R.id.homewk_state);
			holder.itemCredit = (TextView) convertView.findViewById(R.id.homewk_credit);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		if(itemInfo.fileurl!=null){
			GlideImageUtils.setImageLoader(context, itemInfo.fileurl.fileurl_02,
					holder.itemAvatar, R.drawable.default_avator);
		}
		
		holder.itemButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				listener.onClickMenu(v, position);
			}
		});
		holder.itemName.setText(itemInfo.nickname);
		holder.itemTime.setText(TimeMangerUtil.getChinesetimeView(itemInfo.create_time));
		holder.itemContent.setText(itemInfo.content);
		if(itemInfo.read_st.equals("n")){
			holder.itemunread.setText("未确认");
		}else{
			holder.itemunread.setText("已确认");
		}
		holder.itemCredit.setText(itemInfo.commentCount+"");
		holder.itemflower.setText(itemInfo.flower_count+"");
		
		return convertView;
	}
	
	public interface OnHomeWorkListener {
		void onClickMenu(View v, int position);
	}
	
	private class ViewHolder {
		CircularImageView itemAvatar;
		ImageView itemButton;
		TextView itemName;
		TextView itemTime;
		TextView itemContent;
		
		TextView itemflower;
		TextView itemunread;
		TextView itemCredit;
	}
}
